package cl.orange.portal.beans;

import cl.orange.portal.utils.email.EmailService;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.mail.internet.AddressException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;

@Named("viewBean")
@Scope("session")
public class ViewBean implements Serializable {

    private static final long serialVersionUID = -1L;
    private static final Logger LOGGER = LoggerFactory.getLogger(ViewBean.class);
    @Resource(name = "emailServiceImpl")
    private EmailService emailService;

    public String sendMailTestMailSender() {
        LOGGER.debug("aca enviando mailss");
        Map<String, String> datos = new HashMap<String, String>();
        datos.put("usuario", "Usuario testttttt");
        emailService.sendMail(datos, "templateTest.vm", "Testeando el mail", "yamil@orangepeople.cl");
        return "";
    }

    public String sendMailTestInternalLiferay() {
        Map<String, String> datos = new HashMap<String, String>();
        datos.put("usuario", "Usuario testttttt");
        try {
            emailService.sendMailNative(datos, "templateTest.vm", "Testeando el mail", "yamil@orangepeople.cl");
        } catch (AddressException e) {
            LOGGER.error("Falla en envio de Mail: {}", e);
        }
        return "";
    }

    public String sendMailTestInternalLiferayWithCC() {
        Map<String, String> datos = new HashMap<String, String>();
        datos.put("usuario", "Usuario testttttt");
        try {
            emailService.sendMailNative(datos, "templateTest.vm", "Testeando el mail con CCs", "yamil@orangepeople.cl", "yamil@mailinator.com", "yamil2@mailinator.com");
        } catch (AddressException e) {
            LOGGER.error("Falla en envio de Mail: {}", e);
        }
        return "";
    }
}